package thread;

/**
 * 通过interrupt方式，去中断线程
 */
public class Demo7 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(new Runnable() {
            @Override
            public void run() {
                while(!Thread.currentThread().isInterrupted()){
                    System.out.println("转账中");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        //具体如何处理，看catch的代码块
                        break;
                    }
                }
                System.out.println("已停止");
            }
        });
        t1.start();
        Thread.sleep(2000);
        System.out.println("停止转账");
        t1.interrupt();
    }
}
